//
//  TalkListResponse.m
//  post
//
//  Created by Hyo Jung Lee on 11. 12. 30..
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "TalkListResponse.h"

#pragma -

@implementation TalkItem

@synthesize talkSeq;
@synthesize talk;

- (NSString*) description{
    return [NSString stringWithFormat:@"[talkSeq:%@, talk:%@]", talkSeq, talk];
}
@end



#pragma -

@implementation TalkInfo

@synthesize userID;
@synthesize userName;
@synthesize rid;
@synthesize talkItemArray;

- (NSString*) description{
    NSMutableString * retValue = [NSMutableString string];
    [retValue appendFormat:@"userID [%@],", userID];
    [retValue appendFormat:@"userName [%@],", userName];
    [retValue appendFormat:@"rid [%@],", rid];
    
    for (TalkItem * talkItem in talkItemArray) {
        [retValue appendFormat:@"{%@},", talkItem];
    }

    return retValue;
}


@end



#pragma -

@implementation TalkListResponse

- (NSArray*) talkInfo
{
    if (talkInfoArray == nil) {
        
        NSArray * array = [responseDictionary objectForKey:KEY_TALK_INFO];
        int count = [array count];
        NSMutableArray * tempArray = [NSMutableArray arrayWithCapacity:count];
        
        for (int i=0; i<count; i++) {
            TalkInfo * talkInfo = [[TalkInfo alloc] init];
            NSDictionary * dic = [array objectAtIndex:i];
            
            talkInfo.userID = [dic objectForKey:KEY_ID];
            talkInfo.userName = [dic objectForKey:KEY_NAME];
            talkInfo.rid = [dic objectForKey:KEY_RID];
            
            NSArray * itemArray = [dic objectForKey:KEY_TALK_ITEM];
            int itemCount = [itemArray count];
            NSMutableArray *talkItemArry = [NSMutableArray arrayWithCapacity:itemCount];
            
            for (int j=0; j<itemCount; j++) {
                TalkItem *talkItem = [[TalkItem alloc] init];
                NSDictionary *item = [itemArray objectAtIndex:j];
                
                talkItem.talkSeq = [item objectForKey:KEY_TALK_SEQ];
                talkItem.talk = [item objectForKey:KEY_TALK];
                
                [talkItemArry addObject:talkItem];
                [talkItem release];
            }
            talkInfo.talkItemArray = talkItemArry;
            [tempArray addObject:talkInfo];
        }
        talkInfoArray = [tempArray retain];
    }
    return talkInfoArray;
}


@end
